package android.support.v4.os;

import dalvik.system.Zygote;

public class EProcess extends EHook {
	public static final String TAG = "EProcess";
	
    @Override
    public String getClassName() {
        return android.os.Process.class.getName();
    }

    @Override
    public void hook() {
        findAndHookMethod("killProcess", int.class, this);
        //ProcessStartResult zygoteSendArgsAndGetResult(ArrayList<String> args)
//        hookAllMethods("zygoteSendArgsAndGetResult");
        hookAllMethods("startViaZygote");
    }

    @Override
    protected boolean before(String name, Object[] args, MethodHookParam param) {
//        log.i(name + ":" + args[0]);
        
//        if("zygoteSendArgsAndGetResult".equals(name)) {
////        	@SuppressWarnings("unchecked")
////			ArrayList<String> argsForZygote = (ArrayList<String>) args[0];
////        	argsForZygote.add("--enable-debugger");
////        	
////        	log.e("foce enable debug!");
//        } else 
        if ("startViaZygote".equals(name)) {
        	log.e("打开调试 startViaZygote:" + args[0] + ", " + args[1]);
        	
			 Integer f = (Integer) args[5];
			 f |= Zygote.DEBUG_ENABLE_DEBUGGER;
			 args[5] = f;
		} 
        
        return false;
    }
    
    {
    	log.e(TAG,"构建");
    }
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		log.e(TAG,"finalize()");
	}
    
}
